﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using MyApp.Infrastructure.Messages;
using Microsoft.Practices.Composite.Presentation.Events;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Composite.Regions;

namespace MyApp.MainContainer
{
    public partial class MainContainer : UserControl
    {
        public MainContainer()
        {
            InitializeComponent();
            if (DesignerProperties.IsInDesignTool)
                return;

            Messenger.Get<CreateViewMessage>().Subscribe(this.HandleCreateView, ThreadOption.UIThread, true, this.CanHandleCreateView);
        }

        private bool CanHandleCreateView(CreateViewMessageArgs args)
        {
            return args.Position == ViewPosition.Center;
        }

        private void HandleCreateView(CreateViewMessageArgs args)
        {
            this.tabCtrl.Items.Add(new TabItem
            {
                Header = args.Title, Content = args.View.Value,
                VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch,
                HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch
            });
        }
    }
}
